package org.example.rubbish.service.impl;



import org.example.rubbish.entity.DeviceControl;
import org.example.rubbish.mapper.DeviceControlMapper;
import org.example.rubbish.service.DeviceControlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DeviceControlServiceImpl implements DeviceControlService {
    @Autowired
    private DeviceControlMapper deviceControlMapper;

    @Override
    public DeviceControl createOrUpdateControl(DeviceControl control) {
        DeviceControl existing = deviceControlMapper.selectByStationId(control.getStationId());
        if (existing != null) {
            control.setId(existing.getId());
            deviceControlMapper.update(control);
        } else {
            deviceControlMapper.insert(control);
        }
        return deviceControlMapper.selectByStationId(control.getStationId());
    }

    @Override
    public DeviceControl getControlByStationId(Long stationId) {
        return deviceControlMapper.selectByStationId(stationId);
    }
}